package cn.openbiotoken.impl;

import cn.openbiotoken.Rect;

import static java.lang.String.format;

public class RectImpl implements Rect {

    public RectImpl(final int left, final int top, final int width, final int height) {
        if (left < 0) {
            throw new IllegalArgumentException(format("The left should be greater than or equal to 0. Actual left is %d.", left));
        }

        if (top < 0) {
            throw new IllegalArgumentException(format("The top should be greater than or equal to 0. Actual top is %d.", top));
        }

        if (width < 0) {
            throw new IllegalArgumentException(format("The width should be greater than or equal to 0. Actual width is %d.", width));
        }

        if (height < 0) {
            throw new IllegalArgumentException(format("The height should be greater than or equal to 0. Actual height is %d.", height));
        }

        this.left = left;
        this.top = top;
        this.width = width;
        this.height = height;
    }

    private final int left;

    private final int top;

    private final int width;

    private final int height;

    @Override
    public int getLeft() {
        return left;
    }

    @Override
    public int getTop() {
        return top;
    }

    @Override
    public int getWidth() {
        return width;
    }

    @Override
    public int getHeight() {
        return height;
    }

    @Override
    public int getRight() {
        return left + width;
    }

    @Override
    public int getBottom() {
        return top + height;
    }
}
